/**
 * 客户信息 编辑页
 *
 * 作者 ganjun
 * 日期 2024-11-12 14:15:30
 */
layui.use(['jquery','febs', 'form', 'validate'], function () {
    var $ = layui.$,
        febs = layui.febs,
        layer = layui.layer,
        form = layui.form,
        $view = $('#customer-audit'),
        validate = layui.validate;

    form.verify(validate);
    form.render();
    initFormValue();

    function initFormValue() {
        if (customerData) {
            form.val("customer-audit-form", {
                "id": customerData.id,
            });
        }
    }

    form.on('submit(customer-audit-form-submit)', function (data) {
        addOrUpdate(data.field);
        return false;
    });

    function addOrUpdate(data) {
        if(data.status === '2' && data.opinion === ''){
            febs.alert.warn('审核意见不能为空');
            return;
        }
        febs.modal.confirm("审核提示！","是否审核？",function (index){
            if (data.id && data.id.length > 0) {
                data.statusName = $view.find("input[type=radio][name='status']:checked").attr('title');
                febs.postArray(ctx + 'customer/audit', data, function () {
                    layer.closeAll();
                    febs.alert.success('审核成功');
                    // febs.reloadPage();
                    $('#febs-customer').find('#query').trigger('click');
                });
            }
        });
    }
});